import { AbstractPath, File, ModuleExport, Options } from './types';
import { createSFCModule } from './createVueSFCModule';
import { createJSModule, loadModuleInternal } from './toolsWithJsx';

/**
 * Just load and cache given dependencies.
 * @internal
 */
export async function loadDeps(refPath : AbstractPath, deps : AbstractPath[], options : Options) : Promise<void> {

  await Promise.all(deps.map(relPath => loadModuleInternal({ refPath, relPath }, options)))
}


/**
 * Default implementation of handleModule
 */
async function handleModuleInternal(type : string, getContentData : File['getContentData'], path : AbstractPath, options : Options) : Promise<ModuleExport | undefined> {

  switch (type) {
    case '.vue': return createSFCModule((await getContentData(false)) as string, path, options);
    case '.js': return createJSModule((await getContentData(false)) as string, false, path, options);
    case '.mjs': return createJSModule((await getContentData(false)) as string, true, path, options);
    case '.ts': return createJSModule((await getContentData(false)) as string, true, path, {
      ...options,
    });
  }

  return undefined;
}
